package com.fira.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.fira.api.domain.dto.LoginDTO;
import com.fira.common.core.controller.BaseController;
import com.fira.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

/**
 * @author Deng
 */
public abstract class ApiController extends BaseController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public LoginDTO getLogin(HttpServletRequest request) {

        String token = request.getParameter("token");
        token=StringUtils.isEmpty(token)?request.getHeader("token"):token;
        if (StringUtils.isEmpty(token)) {
            return null;
        }
        String str = stringRedisTemplate.opsForValue().get(token);
        if (StringUtils.isEmpty(str)) {
            return null;
        }
        return JSONObject.parseObject(str, LoginDTO.class);
    }
}
